package com.wanglei.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanglei.constants.SystemConstants;
import com.wanglei.domain.ResponseResult;
import com.wanglei.domain.entity.Link;
import com.wanglei.domain.vo.LinkVo;
import com.wanglei.domain.vo.PageVo;
import com.wanglei.service.LinkService;
import com.wanglei.mapper.LinkMapper;
import com.wanglei.utils.BeanCopyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author MrWang
* @description 针对表【sg_link(友链)】的数据库操作Service实现
* @createDate 2023-07-02 20:13:43
*/
@Service
public class LinkServiceImpl extends ServiceImpl<LinkMapper, Link>
    implements LinkService{

    @Autowired
    private LinkMapper linkMapper;

    //查看友链列表
    @Override
    public ResponseResult getAllLink() {
        LambdaQueryWrapper<Link> queryWrapper = new LambdaQueryWrapper<Link>()
                .eq(Link::getStatus, SystemConstants.LINK_STATUS_NORMAL);//友链状态为审核通过
        List<Link> links = linkMapper.selectList(queryWrapper);
        //vo
        List<LinkVo> linkVos = BeanCopyUtils.copyBeanList(links, LinkVo.class);

        return ResponseResult.okResult(linkVos);
    }

    @Override
    public ResponseResult list(Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<Link> queryWrapper = new LambdaQueryWrapper<Link>()
                .eq(Link::getStatus, SystemConstants.LINK_STATUS_NORMAL);//友链状态为审核通过
        Page<Link> page = new Page<>(pageNum,pageSize);
        linkMapper.selectPage(page, queryWrapper);
        List<Link> links = page.getRecords();
        //vo
        BeanCopyUtils.copyBeanList(links,LinkVo.class);

        return ResponseResult.okResult(new PageVo(links,page.getTotal()));
    }
}




